package xin.xihc.jba.sql.join;

import xin.xihc.jba.scan.TableManager;
import xin.xihc.jba.sql.SqlConstants;
import xin.xihc.jba.sql.SqlType;

/**
 * Join
 *
 * @author Leo.Xi
 * @date 2020/8/23
 * @since 1.0
 **/
public abstract class Join implements SqlType {

    protected String tableName; // 表名 + 别名
    protected String on; // ON 关系

    public Join(String tableName, String on) {
        this.tableName = tableName;
        this.on        = on;
    }

    public Join(Class<?> clazz, String as, String on) {
        this.tableName = TableManager.getTable(clazz).getTableName() + SqlConstants.BLANK + as;
        this.on        = on;
    }

    /**
     * 转为SQL语句
     *
     * @return sql
     * @author Leo.Xi
     * @date 2020/1/14
     * @since 0.0.1
     */
    @Override
    public String toSql() {
        return action() + tableName + SqlConstants.ON + this.on;
    }
}